package com.itqf.ipmsys.controller;


import com.itqf.ipmsys.vo.DailyIncomeVO;
import com.itqf.ipmsys.vo.ParkingLotsVO;
import com.itqf.ipmsys.vo.TotalVO;
import com.itqf.ipmsys.service.*;
import com.itqf.ipmsys.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author corn
 * @create 2021-10-10 14:38
 * @Description: ${Description}
 */
@CrossOrigin("*")
@RestController
@RequestMapping("chart")
public class ChartController {

    @Autowired
    private ParkingLotService parkingLotService;

    @Autowired
    private ParkingService parkingService;

    @Autowired
    private ParkingRecordService parkingRecordService;

    @Autowired
    private RepairService repairService;

    @Autowired
    private UserService userService;

    @Autowired
    private DestrictService destrictService;

    @GetMapping("total")
    public R total(){

        //查询停车场总数
        Integer packinglots = parkingLotService.findPackingCount();

        //查询停车位总数
        Integer parkings = parkingService.findParkingCount();

        //查询停车总次数
        Integer parkingRecords = parkingRecordService.findParkingRecordCount();

        //查询总收入
        Integer prices = parkingRecordService.findPrices();

        //查询维修总次数
        Integer maintains = repairService.findRepairs();

        //查询用户总数
        Integer users = userService.findUserTotal();

        TotalVO totalDTO = new TotalVO();
        totalDTO.setPackinglots(packinglots);
        totalDTO.setParkings(parkings);
        totalDTO.setParkingRecords(parkingRecords);
        totalDTO.setPrices(prices);
        totalDTO.setMaintains(maintains);
        totalDTO.setUsers(users);

        return R.ok().setData("totaldata", totalDTO);
    }

    @GetMapping("parkinglots")
    public R parkingLots(){

        List<ParkingLotsVO> parkingLots = destrictService.findIsConnectedParkingLots();

        return R.ok().setData("parkinglots", parkingLots);
    }

    @GetMapping("dailyincome")
    public R dailyIncome(){
        List<DailyIncomeVO> dailyIncomeDTOList = destrictService.findDailyIncome();

        return R.ok().setData("dailyincome", dailyIncomeDTOList);
    }





}
